package com.xhj.springbootproject.service.impl;

import com.xhj.springbootproject.constant.ResultCodeEnum;
import com.xhj.springbootproject.constant.object.BasicUserVO;
import com.xhj.springbootproject.dao.BasicUserDao;
import com.xhj.springbootproject.dao.object.BasicUserDO;
import com.xhj.springbootproject.service.intf.BasicUserService;
import com.xhj.springbootproject.util.HashKit;
import com.xhj.springbootproject.util.JsonResult;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.FastDateFormat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * @author ：Xionghaijun
 * @date ：Created in 2019/7/4 10:58 AM
 * @description：
 */
@Service
public class BasicUserServiceImpl implements BasicUserService {

    private final Logger logger = LoggerFactory.getLogger(BasicUserServiceImpl.class);


    @Autowired
    private BasicUserDao basicUserDao;

    @Override
    public JsonResult insertUser(BasicUserVO basicUserVO) {
        BasicUserDO basicUserDO = new BasicUserDO();
        BeanUtils.copyProperties(basicUserVO, basicUserDO);
        String uuid = UUID.randomUUID().toString().replaceAll("-", "");
        String userPassword = HashKit.md5(basicUserVO.getPassword() + uuid);
        basicUserDO.setUuid(uuid);
        basicUserDO.setUserPassword(userPassword);
        basicUserDO.setUserCode("simp_" + RandomStringUtils.random(10,true,true));
        boolean result = basicUserDao.insertUser(basicUserDO);
        if (result) {
            return JsonResult.getSuccessResult();
        }
        return JsonResult.getFailedResult(ResultCodeEnum.INTERNAL_ERROR, "添加用户失败");
    }

    public static void main(String[] args) {
//        String uuid = UUID.randomUUID().toString().replaceAll("-", "");
//        System.out.println("uuid = " + uuid);
//        String userPassword = HashKit.md5("12345" + uuid);
//        System.out.println("password = "  + userPassword);
//        userPassword = HashKit.md5("12345" + uuid);
//        System.out.println("password = "  + userPassword);
//        System.out.println(FastDateFormat.getInstance("yyyyMMddHHmmss").format(System.currentTimeMillis()) + RandomStringUtils.random(5,true,true));

//        System.out.println(getMaxDouble(1d, 2d, 3d));
//        System.out.println(getMaxDouble(2d, 3d, 1d));
//        System.out.println(getMaxDouble(3d, 1d, 2d));

//        int[] arr = {1,2,3};
//        for (int i = 0; i < arr.length; i++) {
//            System.out.print(arr[i] + "\t");
//        }

        String[] str = new String[5];
        for(String myStr : str){
            myStr = "atguigu";
            System.out.println(myStr);
        }
        for(int i = 0;i < str.length;i++){
            System.out.println(str[i]);
        }

    }

    public static double getMaxDouble(double d1, double d2, double d3) {

        return d1 > d2 ? (d3 > d1 ? d3 : d1) : (d3 > d2 ? d3 : d2);
    }

}
